<!--
 * @Author: weidewei
 * @Date: 2025-11-19 14:08:29
 * @LastEditors: weidewei
 * @LastEditTime: 2025-11-19 15:07:06
 * @Description: 
 * @FilePath: \2025-front-face\html&css\瀑布流布局.html
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .item-1 {
      height: 200px;
      border: 1px solid red;
    }
    .item-2 {
      height: 300px;
      border: 1px solid red;
    }
    .item-3 {
      height: 250px;
      border: 1px solid red;
    }
    .item-4 {
      height: 180px;
      border: 1px solid red;
    }
    .item-5 {
      height: 320px;
      border: 1px solid red;
    }
    .item-6 {
      height: 220px;
      border: 1px solid red;
    }
    .item-7 {
      height: 280px;
      border: 1px solid red;
    }
    .item-8 {
      height: 190px;
      border: 1px solid red;
    }
    .waterfall {
      /* 将一个元素的内容分成指定数量的列 */
      column-count: 5;
      /* 设置元素列之间的间隔 */
      column-gap: 100px;
      width: 100%;
    }
    .waterfall-item {
      /* 多列布局防止内容断裂 */
      break-inside: avoid;
      margin-bottom: 20px;
      background: white;
      border-radius: 8px;
      padding: 15px;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
    /* 响应式设计 */
    @media (max-width: 768px) {
      .waterfall {
        column-count: 2; 
      }
    }

    @media (max-width: 480px) {
      .waterfall {
        column-count: 1; 
      }
    }
  </style>
  <body>
    <div class="waterfall">
      <div class="item-1 waterfall-item">1</div>
      <div class="item-2 waterfall-item">2</div>
      <div class="item-3 waterfall-item">3</div>
      <div class="item-4 waterfall-item">4</div>
      <div class="item-5 waterfall-item">5</div>
      <div class="item-6 waterfall-item">6</div>
      <div class="item-7 waterfall-item">7</div>
      <div class="item-8 waterfall-item">8</div>
    </div>
  </body>
</html>
